#include <Windows.h>
#include <stdio.h>

int __getmainargs(int *, LPSTR **, LPSTR **, int, int *);

void mainCRTStartup()
{
    HWND hWnd;
    hWnd = GetForegroundWindow();
    if (hWnd)
    {
        int argc;
        char **argv;
        char **envp;
        int startup_info = 0;
        int need_im = -1;
        int real_im;
        __getmainargs(&argc, &argv, &envp, 0, &startup_info);
        if (argv[1])
        {
            need_im = atoi(argv[1]);
            SendMessageA(hWnd, WM_INPUTLANGCHANGEREQUEST, 0, need_im);
        }
        real_im = LOWORD(GetKeyboardLayout(GetWindowThreadProcessId(hWnd, 0)));
        if (need_im < 0)
        {
            printf("%u\n", real_im);
            exit(0);
        }
        if (real_im == need_im)
            exit(0);
    }
    exit(1);
}